package com.ruoyi.project.search.viewInjobHistory.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.search.viewInjobHistory.domain.ViewInJobHistory;
import com.ruoyi.project.search.viewInjobHistory.service.IViewInJobHistoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 入库流水Controller
 * 
 * @author ruoyi
 * @date 2023-08-29
 */
@Controller
@RequestMapping("/search/viewInjobHistory")
public class ViewInJobHistoryController extends BaseController
{
    private String prefix = "search";

    @Autowired
    private IViewInJobHistoryService viewInJobHistoryService;

    @GetMapping()
    public String viewInjobHistory()
    {
        return prefix + "/viewInjobHistory";
    }

    /**
     * 查询入库流水列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ViewInJobHistory viewInJobHistory)
    {
        startPage();
        List<ViewInJobHistory> list = viewInJobHistoryService.selectViewInJobHistoryList(viewInJobHistory);
        return getDataTable(list);
    }

    /**
     * 导出入库流水列表
     */
    @Log(title = "入库流水", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ViewInJobHistory viewInJobHistory)
    {
        List<ViewInJobHistory> list = viewInJobHistoryService.selectViewInJobHistoryList(viewInJobHistory);
        ExcelUtil<ViewInJobHistory> util = new ExcelUtil<ViewInJobHistory>(ViewInJobHistory.class);
        return util.exportExcel(list, "入库流水数据");
    }

    /**
     * 新增入库流水
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存入库流水
     */
    @Log(title = "入库流水", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ViewInJobHistory viewInJobHistory)
    {
        return toAjax(viewInJobHistoryService.insertViewInJobHistory(viewInJobHistory));
    }

    /**
     * 修改入库流水
     */
    @GetMapping("/edit/{jobDetailId}")
    public String edit(@PathVariable("jobDetailId") String jobDetailId, ModelMap mmap)
    {
        ViewInJobHistory viewInJobHistory = viewInJobHistoryService.selectViewInJobHistoryByJobDetailId(jobDetailId);
        mmap.put("viewInJobHistory", viewInJobHistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存入库流水
     */
    @Log(title = "入库流水", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ViewInJobHistory viewInJobHistory)
    {
        return toAjax(viewInJobHistoryService.updateViewInJobHistory(viewInJobHistory));
    }

    /**
     * 删除入库流水
     */
    @Log(title = "入库流水", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(viewInJobHistoryService.deleteViewInJobHistoryByJobDetailIds(ids));
    }
}
